home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / encryp1r / functs-s.bas < prev    next >
Encoding:
BASIC Source File  |  1999-08-24  |  2.1 KB  |  74 lines

  1. Attribute VB_Name = "Functions_String"
  2. Option Explicit
  3.  
  4.  
  5. Public Function TrimNull(ByVal What As String)
  6.  
  7.     ' Function: TrimNull
  8.     '
  9.     ' Takes a string as input and returns
  10.     ' a string with  all instances of the
  11.     ' null character Chr$(0), leading and
  12.     ' trailing spaces, and vbCrLf removed.
  13.     
  14.     What = Trim$(What)
  15.     If InStr(What, Chr(0)) <> 0 Then What = RemoveChar(What, Chr(0))
  16.     If InStr(What, vbCrLf) <> 0 Then What = RemoveChar(What, vbCrLf)
  17.         
  18.     Do: DoEvents
  19.     If Right(What, 1) = Chr(10) Or Right(What, 1) = Chr(13) Then What = Mid(What, 1, Len(What) - 1)
  20.     Loop Until Right(What, 1) <> Chr(10) And Right(What, 1) <> Chr(13)
  21.     
  22.     Do: DoEvents
  23.     If Left(What, 1) = Chr(10) Or Left(What, 1) = Chr(13) Then What = Mid(What, 2)
  24.     Loop Until Left(What, 1) <> Chr(10) And Left(What, 1) <> Chr(13)
  25.     
  26.     TrimNull = What
  27.     
  28. End Function
  29.  
  30. Public Function RemoveChar$(ByVal Buf As String, ByVal Char As String)
  31.  
  32.     ' Function: RemoveChar$
  33.     '
  34.     ' Removes all occurrences of 'Char' in 'Buf'
  35.     ' and returns the new string
  36.     
  37.     Dim Check%
  38.     Dim LeftOf$, RightOf$
  39.     
  40.     Do
  41.         DoEvents
  42.         Check% = InStr(Buf$, Char$)
  43.         If Check% > 0 Then
  44.             LeftOf$ = Left(Buf$, Check% - 1)
  45.             RightOf$ = Right(Buf$, Len(Buf$) - Check%)
  46.             Buf$ = LeftOf$ & RightOf$
  47.         End If
  48.     Loop Until Check% = 0
  49.     
  50.     RemoveChar$ = Buf$
  51.  
  52. End Function
  53.  
  54. Public Function StripQuotes(ByVal StringWithQuotes As String) As String
  55.  
  56.     ' Function: StripQuotes
  57.     '
  58.     ' Returns: This function simply returns StringWithQuotes
  59.     ' with quotation marks on the left and right side stripped away.
  60.     
  61.     If StringWithQuotes = "" Then Exit Function
  62.     
  63.     If Left(StringWithQuotes, 1) = Chr(34) Then
  64.         StringWithQuotes = Mid(StringWithQuotes, 2)
  65.     End If
  66.     
  67.     If Right(StringWithQuotes, 1) = Chr(34) Then
  68.         StringWithQuotes = Mid(StringWithQuotes, 1, Len(StringWithQuotes) - 1)
  69.     End If
  70.     
  71.     StripQuotes = StringWithQuotes
  72.     
  73. End Function
  74.